$(function(){
	/* 点击任意日期时触发该函数 */
	$('#cc').calendar({
		onSelect : function(date) {
			//alert(date.getFullYear()+":"+(date.getMonth()+1)+":"+date.getDate());
			/*修改内部数据  */
			$("#ddcalendar").window("open");	
			$('#huo_dgcc').datagrid({
				//请求地址
			    url:'../check/getcalendarAffair',
			    columns:[[
			    	{field:'',title:'',checkbox:true},
					{field:'affairId',title:'行政事务编号',width:'10%'},
					{field:'affairBegintime',title:'开始时间',width:'20%'},
					{field:'affairEndtime',title:'结束时间',width:'20%'},
					{field:'theam',title:'主题',width:'10%'},
					{field:'kind',title:'种类',width:'8%'},
					{field:'affairType',title:'事务类型',width:'10%'},
					{field:'dept',title:'部门',width:'15%'},
					{field:'emp',title:'员工',width:'8%'}
			    ]],
			    fit:true,
			    fitColumns:true,
			    //隔行变色
			    striped:true,
			    //显示行号
			    rownumbers:true,
			    //设置单选
			    singleSelect:true,
				//显示分页栏
				pagination:true,
				//设置每页大小
				pageSize:5,
				//可选的每页大小
				pageList:[5,10,20,50],
				//绑定一个点击表格事件
				onClickCell:onClickCell
			});
		}
	});
	
	
});

 function searchname(value){
	 $('#huo_dgcc').datagrid('load','getempyename?ename='+value);
} 
 
 
 var editIndex = undefined;
 
	function onClickCell(index, field){
		if (editIndex != index){
			if (endEditing()){
				$('#huo_dgcc').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				var ed = $('#huo_dgcc').datagrid('getEditor', {index:index,field:field});
				if (ed){
					($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
				}
				editIndex = index;
			} else {
				setTimeout(function(){
					$('#huo_dgcc').datagrid('selectRow', editIndex);
				},0);
			}
		}
	}
	
	function append(){
		if (endEditing()){
			$('#huo_dgcc').datagrid('appendRow',{eid:'',ename:'',salary:'',did:''});
			editIndex = $('#huo_dgcc').datagrid('getRows').length-1;
			$('#huo_dgcc').datagrid('selectRow', editIndex)
					.datagrid('beginEdit', editIndex);
		}
	}
	function removeit(){
		if (editIndex == undefined){return}
		$('#huo_dgcc').datagrid('cancelEdit', editIndex)
				.datagrid('deleteRow', editIndex);
		editIndex = undefined;
	}
	function accept(){
		if (endEditing()){
			$('#huo_dgcc').datagrid('acceptChanges');
		}
	}
	function reject(){
		$('#huo_dgcc').datagrid('rejectChanges');
		editIndex = undefined;
	}
	function getChanges(){
		//var rows = $('#dg').datagrid('getChanges');
		//alert(JSON.stringify(rows));
		var inserted=$('#huo_dgcc').datagrid('getChanges','inserted');
		alert(JSON.stringify(inserted));
		
		var updated=$('#huo_dgcc').datagrid('getChanges','updated');
		alert(JSON.stringify(updated));
		
		var deleted=$('#huo_dgcc').datagrid('getChanges','deleted');
		alert(JSON.stringify(deleted));
	}